package com.oocl.service.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.oocl.dao.CustomerDao;
import com.oocl.exception.MyException;
import com.oocl.pojo.Customer;
import com.oocl.service.CustomerService;


@Service("cSer")
public class CustomerServiceImpl implements CustomerService{
	private CustomerDao cDao;
	
	@Autowired
	public void setcDao(CustomerDao cDao) {
		this.cDao = cDao;
	}
	@Override
	public Customer addCustomer(Customer c) {
		Customer cut = null;
		try {
			cut = cDao.addCustomer(c);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new MyException("添加出错");
		}
		return cut;
	}
	@Override
	public List<Customer> findAllCustomers() {
		List<Customer> list;
		try {
			list = cDao.findAllCustomers();
		} catch (SQLException e) {
			e.printStackTrace();
			throw new MyException("查询出错");
		}
		return list;
	}
	@Override
	public Customer deleteCustomer(String id) {
		Customer c = null;
		try {
			c= cDao.deleteCustomer(id);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new MyException("删除出错");
		}
		return c;
	}
	@Override
	public Customer FindCustomerById(String id) {
		Customer c = null;
		try {
			c = cDao.FindCustomerById(id);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new MyException("查询出错");
		}
		return c;
	}
	@Override
	public Customer updateCustomer(Customer c) {
		Customer cut =null;
		try {
			cut= cDao.updateCustomer(c);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new MyException("修改出错");
		}
		return cut;
	}
	

}
